#include "gatling_bullet.h"

GATLING_BULLET::GATLING_BULLET(QPointF start_point, QTimeLine *global_tl, SCENE *scene, CASH *cash):QGraphicsObject()
{

    this->setData(777,"Shuttle_Bullet");

    this->setObjectName("Shuttle_Bullet");

    this->cash = cash;
    border = new QPainterPath();

    pix = cash->cash_pixmap->value("Res/weapons/gatling/1.png");

    point = 2;
    speed = 20;

    collisia_control = new COLLISIA_CONTROL(scene,((QGraphicsObject*)this),this,global_tl,cash,10);

    this->setPos(start_point);

    connect(collisia_control,SIGNAL(Collisia(QPointF,int)),this,SLOT(Damage_Detected(QPointF,int)));

    QTimer::singleShot(100, this, SLOT(set_shape()));
}

GATLING_BULLET::~GATLING_BULLET(){}

QRectF GATLING_BULLET::boundingRect() const
{
    return QRectF(0, 0, pix->width(), pix->height());
}

QPainterPath GATLING_BULLET::shape() const
{
    return *border;
}

void GATLING_BULLET::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
    painter->save();
    painter->drawPixmap(0, 0, *pix);
    painter->restore();
}

int GATLING_BULLET::type() const
{

    return point;

}

void GATLING_BULLET::slot_run()
{
    this->setPos(this->pos().x(), this->pos().y() - speed);

    if(this->pos().y() <  -(this->boundingRect().height())){
        this->deleteLater();
    }
}

void GATLING_BULLET::Damage_Detected(QPointF a, int d)
{
    a=QPointF();

    point-=d;

    if(point<=0) this->scene()->removeItem(this);
}

void GATLING_BULLET::set_shape()
{
    border = cash->cash_poly->value(DEF_BULLETS_PATH + "gatling/gatling.poly");
}
